import os
import shutil
import datetime

# 设置时间戳格式
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")

# 创建备份目录
backup_dir = f"Backup_{timestamp}"
if not os.path.exists(backup_dir):
    os.makedirs(backup_dir)

# 检查并备份文件
for letter in "ABCDEFGHIJK":
    filename = f"{letter}.cpp"
    if os.path.exists(filename):
        # 备份文件
        backup_filename = os.path.join(backup_dir, f"{filename}_{timestamp}.bak")
        shutil.copy2(filename, backup_filename)
        # 清空原文件
        with open(filename, 'w') as f:
            pass
    else:
        # 创建空文件
        with open(filename, 'w') as f:
            pass

print("Backup and clear operation completed.")